// index.js
const {request} = require('../../utils/util.js')
Component({
  data: {
    title: "临时作业",
    list:[],
    page:1,
    pages:1,
    rowColsAvater: [{ size: '96rpx', type: 'circle' }],
    rowColsImage: [{ size: '96rpx', type: 'rect' }],
    rowColsContent: [{ width: '50%' }, { width: '100%' }],
    usertype:""
  },
  methods: {
    onLoad: function () {
      this.getList()
      const userInfo = wx.getStorageSync('userinfo'); // 读取缓存中的 usertype
      console.log("userInfo",userInfo)
      const usertype = userInfo.usertype;
      this.setData({
        usertype:usertype
      })
    },
    getList(){
      wx.showLoading({
        title: '加载中',
      })
      let that = this
      let page = that.data.page
      let list = that.data.list
      request('GET', 'api.TempJob/getList', {
        page:page
      }).then(res => {
        if(res.code==1){
          let data = res.data.list
          list = list.concat(data)
          that.setData({
            list:list,
            page:page+1,
            pages:res.data.page.pages
          })
        }else{
          wx.showToast({
            title: res.info,
            icon: 'none',
            duration: 2000
          })
        }
        wx.hideLoading()
      }).catch(err => {
        console.error('Error:', err);
      });
    },
    bindscrolltolower(){
      console.log('scrolltolower')
      if(this.data.page>this.data.pages){
        wx.showToast({
          title: '没有更多了',
          icon: 'none',
          duration: 1000
        })
        return
      }else{
        this.getList()
      }

    },
    add(e){
      console.log("toDeatil",e)

      wx.navigateTo({
        url: '/pages/temp_job_save/temp_job_save'
      })
    }




  },
})
